'use strict';
Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
const p = require('../../stringify/stringifyNumber.cjs');
function u(e, t) {
  const n = e[0],
    a = n === '-' || n === '+' ? e.substring(1) : e,
    r = i => (t ? BigInt(i) : Number(i)),
    s = a
      .replace(/_/g, '')
      .split(':')
      .reduce((i, o) => i * r(60) + r(o), r(0));
  return n === '-' ? r(-1) * s : s;
}
function l(e) {
  let { value: t } = e,
    n = i => i;
  if (typeof t == 'bigint') n = i => BigInt(i);
  else if (isNaN(t) || !isFinite(t)) return p.stringifyNumber(e);
  let a = '';
  t < 0 && ((a = '-'), (t *= n(-1)));
  const r = n(60),
    s = [t % r];
  return (
    t < 60
      ? s.unshift(0)
      : ((t = (t - s[0]) / r),
        s.unshift(t % r),
        t >= 60 && ((t = (t - s[0]) / r), s.unshift(t))),
    a +
      s
        .map(i => String(i).padStart(2, '0'))
        .join(':')
        .replace(/000000\d*$/, '')
  );
}
const d = {
    identify: e => typeof e == 'bigint' || Number.isInteger(e),
    default: !0,
    tag: 'tag:yaml.org,2002:int',
    format: 'TIME',
    test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+$/,
    resolve: (e, t, { intAsBigInt: n }) => u(e, n),
    stringify: l,
  },
  b = {
    identify: e => typeof e == 'number',
    default: !0,
    tag: 'tag:yaml.org,2002:float',
    format: 'TIME',
    test: /^[-+]?[0-9][0-9_]*(?::[0-5]?[0-9])+\.[0-9_]*$/,
    resolve: e => u(e, !1),
    stringify: l,
  },
  c = {
    identify: e => e instanceof Date,
    default: !0,
    tag: 'tag:yaml.org,2002:timestamp',
    test: RegExp(
      '^([0-9]{4})-([0-9]{1,2})-([0-9]{1,2})(?:(?:t|T|[ \\t]+)([0-9]{1,2}):([0-9]{1,2}):([0-9]{1,2}(\\.[0-9]+)?)(?:[ \\t]*(Z|[-+][012]?[0-9](?::[0-9]{2})?))?)?$',
    ),
    resolve(e) {
      const t = e.match(c.test);
      if (!t)
        throw new Error('!!timestamp expects a date, starting with yyyy-mm-dd');
      const [, n, a, r, s, i, o] = t.map(Number),
        y = t[7] ? Number((t[7] + '00').substr(1, 3)) : 0;
      let g = Date.UTC(n, a - 1, r, s || 0, i || 0, o || 0, y);
      const m = t[8];
      if (m && m !== 'Z') {
        let f = u(m, !1);
        Math.abs(f) < 30 && (f *= 60), (g -= 6e4 * f);
      }
      return new Date(g);
    },
    stringify: ({ value: e }) =>
      e.toISOString().replace(/((T00:00)?:00)?\.000Z$/, ''),
  };
exports.floatTime = b;
exports.intTime = d;
exports.timestamp = c;
